package com.ls.demo.service;

import cn.hutool.core.util.ObjectUtil;
import com.ls.demo.common.enums.ResultCodeEnum;
import com.ls.demo.entity.Account;
import com.ls.demo.entity.SuperAdmin;
import com.ls.demo.exception.CustomException;
import com.ls.demo.mapper.SuperAdminMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class SuperAdminService {
    @Resource
    private SuperAdminMapper superAdminMapper;

    public SuperAdmin login(Account account){
        SuperAdmin superAdmin = superAdminMapper.selectByUsername(account.getUsername());
        if(ObjectUtil.isNull(superAdmin)){
            throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
        }
        if(!superAdmin.getPassword().equals(account.getPassword())){
            throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
        }
        return superAdmin;
    }
}
